package main

type LastWarningT struct {
	WarningType int
	RepeatTimes int
}

type LastPressureT struct {
	Temperature              int
	Pressure                 float32
	ErrorPressureRepeatTimes int
}

type LastDataT struct {
	CardId             int
	Sn                 int
	LastPressure       LastPressureT
	WarningRepeatTimes int
}

type LastData struct {
	warningRepeatTimes       int
	errorPressureRepeatTimes int
	datas                    map[string][]*LastDataT
}

func NewLastData(warningRepeatTimes, errorPressureRepeatTimes int) *LastData {
	ld := LastData{warningRepeatTimes: warningRepeatTimes,
		errorPressureRepeatTimes: errorPressureRepeatTimes,
		datas:                    make(map[string][]*LastDataT)}

	return &ld
}

func (p *LastData) GetData(rid string, cardId, sn int) *LastDataT {
	datas, ok := p.datas[rid]
	if !ok {

		datas = make([]*LastDataT, 0)
		p.datas[rid] = datas
	}

	var pld *LastDataT
	for i := 0; i < len(datas); i++ {
		pld = datas[i]
		if pld.CardId == cardId && pld.Sn == sn {
			return pld
		}
	}

	ld := LastDataT{CardId: cardId, Sn: sn, WarningRepeatTimes: 0}
	datas = append(datas, &ld)
	p.datas[rid] = datas

	return &ld
}

/*

func (p *LastData) SavePressure(rid string, cardId, sn int, pressure float32, Temperature int) {

	if p.warningRepeatTimes > 0 {
		ld := p.GetData(rid, cardId, sn)
		ld.LastPressure.Pressure, ld.LastPressure.Temperature = pressure, Temperature

		ld.WarningRepeatTimes = 0
	}
}


func (p *LastData) GetPressure(rid string, cardId, sn int) (pressure float32, Temperature, WarningRepeatTimes int) {

	if p.warningRepeatTimes > 0 {
		ld := p.GetData(rid, cardId, sn)
		return ld.LastPressure.Pressure, ld.LastPressure.Temperature, ld.WarningRepeatTimes
	}

	return 0.0, 0, 0
}
*/
